
package com.yonyou.gmmc.service.SAInterface.controller;

import org.apache.log4j.Logger;
import org.marketing.common.HttpClientUtil;
import org.marketing.common.dms.http.HttpCommonUtil;
import org.marketing.common.dto.customerInfo.CarInfoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.gmmc.service.SAInterface.constant.SAInterfaceConstant;
import com.yonyou.gmmc.service.SAInterface.model.ResultOwnerAuthenticate;
import com.yonyou.gmmc.service.SAInterface.model.TmCreateQrCode;
import com.yonyou.gmmc.service.SAInterface.service.SAinterfaceService;
import com.yonyou.gmmc.service.SAInterface.util.JsonHelper;

import io.swagger.annotations.Api;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.persistence.Column;
import javax.servlet.http.HttpServletRequest;

/**
 * @author Administrator TODO description
 * @date 2017年4月11日
 */
@SuppressWarnings("unused")
@RestController
@RequestMapping(value = SAInterfaceConstant.BASE_PATH + "/" + SAInterfaceConstant.VERSION)
@Api("SA移动化接口")
public class SAInterfaceController {

	private Logger logger = Logger.getLogger(SAInterfaceController.class);

	@Autowired
	private SAinterfaceService saInterfaceService;

	/**
	 * 根据传入的vin码生成对应的二维码信息
	 * 
	 * @param vin
	 *            车架号
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/GenerateQrCode", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public @ResponseBody Map<String, Object> GenerateQrCode(HttpServletRequest request) throws Exception {
		Map<String, Object> QrCodeUrl = new HashMap<String, Object>();
		try {
			String vin = request.getParameter("vin");
			String engine = request.getParameter("engine");
			String phone = request.getParameter("phone");
			String dealerCode=request.getParameter("dealercode");
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("vin", vin);
			map.put("engine", engine);
			map.put("phone", phone);
			map.put("dealerCode", dealerCode);
			QrCodeUrl = saInterfaceService.GenerateQrCode(map);
		} catch (Exception e) {
			logger.error(new Exception(e));
			logger.info("抛出异常了-----------"+e.getMessage());
			QrCodeUrl.put("url", null);
			QrCodeUrl.put("state", SAInterfaceConstant.STATE_CODE_DEFEATED);
			QrCodeUrl.put("message", "二维码生成异常");
		}

		return QrCodeUrl;
	}

}
